package ar.edu.utn.frsf.tpae.a2012.g02.dao.implementacion;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ar.edu.utn.frsf.tpae.a2012.g02.dao.ClienteDAO;
import ar.edu.utn.frsf.tpae.a2012.g02.models.Cliente;

@Component
public class ClienteHibernateDAO extends GenericHibernateDAO<Cliente> implements ClienteDAO {

	// Setter utilizado por Spring.
	@Autowired(required = true)
	private SessionFactory sessionFactory;

	private Session getCurrentSession() {
		return sessionFactory.getCurrentSession();
	}

	@Override
	public Cliente getByDni(String dni) {
		Query query = getCurrentSession().createQuery("from " + Cliente.class.getName() + " where dni = :dni");
		query.setString("dni", dni);
		return (Cliente) query.uniqueResult();
	}
}
